﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

namespace DongFangGuoKai.WMSPlatform.Commn.AppsetingsModule
{
    /// <summary>
    /// system配置文件管理类
    /// </summary>
    public class ConfigManageHelper
    {
        static IConfiguration _config;
        static ConfigManageHelper()
        {
            _config = new ConfigurationBuilder()
                .Add(new JsonConfigurationSource { Path = "system.json", ReloadOnChange = true })
                .Build(); 
        }
        public static string ServiceAssemblyPath
        {
            get
            {
                try
                {
                    return _config.GetSection("ServiceAssemblyPath").Value;
                }
                catch
                {
                    return "";
                }
            }
        }
        public static string NumberSystemServicePath
        {
            get
            {
                try
                {
                    return _config.GetSection("NumberSystemServiceUrl").Value;
                }
                catch
                {
                    return "";
                }
            }
        }
        public static string LIMSServicePath
        {
            get
            {
                try
                {
                    return _config.GetSection("LIMSServiceUrl").Value;
                }
                catch
                {
                    return "";
                }
            }
        }
        public static string TMSServicePath
        {
            get
            {
                try
                {
                    return _config.GetSection("TMSServiceUrl").Value;
                }
                catch
                {
                    return "";
                }
            }
        }

        public static string AgvServicePath
        {
            get
            {
                try
                {
                    return _config.GetSection("AgvServiceUrl").Value;
                }
                catch
                {
                    return "";
                }
            }
        }


        public static string Get(string? key, bool isConn = false)
        {
            string value;
            if (string.IsNullOrEmpty(key)) return null;
            try
            {
                if (isConn)
                {
                    value = _config.GetConnectionString(key);
                }
                else
                {
                    value = _config[key];
                }
            }
            catch (Exception ex)
            {
                value = null;

            }

            return value;
        }

    }
}
